package cn.demo.springcloud.web;
import java.util.List;

import cn.demo.springcloud.pojo.Product;
import cn.demo.springcloud.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;

@Controller
public class ProductController {
 
	@Autowired
    ProductService productService;
	
    @RequestMapping("/products")
    public Object products(Model m, @RequestHeader(value = "user", required = false) String user) {
    	List<Product> ps = productService.listProducts();
    	m.addAttribute("ps", ps);
    	if(StringUtils.isEmpty(user)){
            user = "no gateway";
        }
        m.addAttribute("user", user);
        return "products";
    }

}